﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class TraLoiThacMac : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void TraLoiThacMacTM(object sender, EventArgs e)
    {
        string tieuDe = txtTieuDeTM.Text;
        string noiDung = txtNoiDungTM.Text;
        string fromEmail = TextBox1.Text;
        string password = TextBox2.Text;
        Button btn = (Button)sender;
        string mathacmac = btn.CommandArgument;

        string sql = "select * from thacmac where mathacmac = @mathacmac";
        DataTable table = Database.GetData(sql, "@mathamac", mathacmac);
        string username = "";
        foreach (DataRow row in table.Rows)
        {
            username = row["username"].ToString();
        }

        string sql2 = "SELECT * FROM THANHVIEN WHERE username = @username";
        DataTable table2 = Database.GetData(sql2, "@username", username);
        string email = "";
        foreach (DataRow row in table2.Rows)
        {
            email = row["email"].ToString();
        }

        sendmail send = new sendmail();
        int t = send.Send(fromEmail, password, email, tieuDe, noiDung);

        string sql3 = "update thacmac set tinhtrang = 1 where mathacmac = @mathacmac";
        Database.ExecuteNonQuery(sql3, "@mathacmac", mathacmac);
    }
}